﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;


namespace IHISCETeim.Web.MachineSys.XZModel
{
    public partial class XZKaoQinList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "XZKaoQinList";
            }
        }
        #region 属性 (查询条件)


        protected string KQID
        {
            get
            {
                return GetRequestValue<string>("KQID", "");

            }
        }

        protected string GongHao
        {
            get
            {
                return GetRequestValue<string>("GongHao", "");

            }
        }

        protected string KQType
        {
            get
            {
                return GetRequestValue<string>("KQType", "");
            }
        }

        protected int Year
        {
            get
            {
                return GetRequestValue<int>("year", DateTime.Now.Year);
            }
        }
        protected int Month
        {
            get
            {
                return GetRequestValue<int>("Month", DateTime.Now.Month);
            }
        }

        protected string colMonth
        {
            get
            {
                return Year.ToString() + "-" + Month.ToString();
            }
        }
        protected string stated
        {
            get
            {
                return colMonth + "-" + KQDateFrom.ToString();
            }
        }

        protected string endd
        {
            get
            {
                DateTime dt = DateTime.Now;
                try
                {
                    dt = Convert.ToDateTime(colMonth + "-" + KQDateTo.ToString());
                }
                catch
                {
                    dt = Convert.ToDateTime(colMonth + "-01").AddMonths(1).AddDays(-1);
                }
                return dt.ToString("yyyy-MM-dd");
            }
        }


        protected int KQDateFrom
        {
            get
            {
                return GetRequestValue<int>("KQDateFrom", 1);
            }
        }

        protected int KQDateTo
        {
            get
            {
                return GetRequestValue<int>("KQDateTo",DateTime.Now.Day);
            }
        }
        /// <summary>
        /// 当前排序字段
        /// </summary>
        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "KQDate" : base.orderField;
            }
        }
        /// <summary>
        /// 当前排序方式
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "Desc" : base.orderDirection;
            }
        }

        

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
            this.AddLog(Permission.查看, GetSql());
        }

        protected void DataBind()
        {

            this.rpMenu.DataSource = XZKaoQinController.GetPagination(GetSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataBind();
        }

        protected string GetValue(object _KQType, object _KQValue)
        {
            string KQType = _KQType.ToString();
            decimal KQValue = Convert.ToDecimal( _KQValue);

            switch(KQType)
            {
                case "加班":
                    return KQValue.ToString("f1")+"小时";
                    break;
                case "迟到":                   
                case "早退":
                    return KQValue.ToString("f0")+"分钟";
                    break;
                case "请假":
                    return KQValue.ToString("f6")+"天";
                    break;
                default:
                    return KQValue.ToString("f0")+"次";
                    break;
            }
           // Convert.ToString("KQType") == "加班" ? "小时" : Convert.ToString("KQType") == "迟到" ? "分钟" : Convert.ToString("KQType") == "早退" ? "分钟" : Convert.ToString("KQType") == "请假" ? "天" : "次"

        }

        protected string GetSql()
        {
            string wheresql = "";



            string ItemCodeSQL = "";
            if (!string.IsNullOrEmpty(GongHao))
            {
                ItemCodeSQL = string.Format(" (GongHao like '%{0}%' or  RealName like '%{0}%' ) ", GongHao);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + ItemCodeSQL;
                }
                else
                {
                    wheresql = ItemCodeSQL;
                }
            }

            string DOWNSQL = "";
            if (!string.IsNullOrEmpty(KQType))
            {
                DOWNSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("KQType", QueryOperatorsEnum.等于, KQType);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + DOWNSQL;
                }
                else
                {
                    wheresql = DOWNSQL;
                }
            }

            string KQDateSQL = "";
            //if (!string.IsNullOrEmpty(stated))
            //{
                KQDateSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("KQDate", QueryOperatorsEnum.范围, stated + " 00:00:00|" + endd + " 23:59:59");
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + KQDateSQL;
                }
                else
                {
                    wheresql = KQDateSQL;
                }
           // }

            string KQIDSQL = "";
            if (!string.IsNullOrEmpty(KQID))
            {
                KQIDSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("KQID", QueryOperatorsEnum.等于, KQID);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + KQIDSQL;
                }
                else
                {
                    wheresql = KQIDSQL;
                }
            }

            return wheresql;
        }

        protected string GetYearList()
        {
            string liTemplete = "<option value='{0}' {1}>{0}年</option>";
            string rHtml = "";
            int nowYear = DateTime.Now.Year;
            for (int i = (nowYear - 3); i <= nowYear; i++)
            {
                rHtml = rHtml + string.Format(liTemplete, i, i == Year ? "selected" : "");
            }
            return rHtml;
        }

        protected string GetDayList(int day)
        {
            string liTemplete = "<option value='{0}' {1}>{0}日</option>";
            string rHtml = "";
            int nowYear = 31;
            for (int i = 1; i <= nowYear; i++)
            {
                rHtml = rHtml + string.Format(liTemplete, i, i == day ? "selected" : "");
            }
            return rHtml;
        }

    }
}